package com.itttq.im.utils;

import com.itttq.im.common.constant.Constant;

import java.security.SecureRandom;

public class GenUtil {
    /**
     * 获取随机数
     *
     * @param len
     * @return
     */
    public static int getRandomInt(int len) {
        return new SecureRandom().nextInt(len);
    }

    public static String getParamFromUri(String uri, String key) {
        if (null == uri || !uri.contains(Constant.QUESTION_MARK)) {
            return "";
        }
        String[] params = uri.substring(uri.indexOf(Constant.QUESTION_MARK) + 1).split(Constant.AND);
        for (String p : params) {
            if (p.startsWith(key + Constant.EQUAL)) {
                return p.split(Constant.EQUAL)[1];
            }
        }
        return "";
    }
}
